/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 * 
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class ctrl_CancelProcess_Test 
{

    static testMethod void myUnitTest()
    {
    	// TO DO: implement unit test
		string result = null;
				
    	//For Location Object Records...
        Location__c locationObject = new Location__c();
        locationObject.Name = 'Test Office 112';
        locationObject.Location_Type__c = 'Office';
        locationObject.Rental_Rate__c = 18000;
        insert locationObject;
        
        //For Location Object Records...
        Location__c locationObject1 = new Location__c();
        locationObject1.Name = 'Test Office';
        locationObject1.Location_Type__c = 'Office';
        locationObject1.Rental_Rate__c = 18000;
        insert locationObject1;
        
        Location__c locationObject2 = new Location__c();
        locationObject2.Name = 'Test Land';
        locationObject2.Location_Type__c = 'Land';
        locationObject2.Rental_Rate__c = 18000;
        insert locationObject2;
        
        //Account Object Record...
        Account accountObject = new Account();
        accountObject.Name = 'Test Account';
        //accountObject.LicenseNumber__c = serialObject.id;
        accountObject.License_Application_Step__c = 'Record Created';
        accountObject.License_Application_Type__c = 'New License';
        accountObject.Activity__c = 'Trading - One Activity';
        accountObject.License_Issue_Date__c = system.today();
        accountObject.Master_Account_Flag__c = true;
        accountObject.License_Expiry_Date__c = System.Today().addYears(1);
        insert accountObject;
        
        
        RecordType recordType = [select Id,IsActive,SObjectType,DeveloperName from RecordType where DeveloperName = 'New_Tenancy_Contract' AND SObjectType = 'Tenancy_Contract__c'];
        
        Tenancy_Contract__c tenancyObject = new Tenancy_Contract__c();
        tenancyObject.Location__c = locationObject1.id;
        tenancyObject.RecordTypeId = recordType.id;
        tenancyObject.Tenant__c = accountObject.id;
        tenancyObject.Tenancy_Contract_Start_Date__c = accountObject.License_Issue_Date__c;
        tenancyObject.Tenancy_Contract_Expiry_Date__c = date.TODAY().addyears(1).adddays(-1);
        insert tenancyObject;
        
        //For Update the Location with the current Locaiton...
        locationObject1.Current_Tenancy_Contract__c = tenancyObject.Id;
        update locationObject1;
    	
    	Amendment__c amendmentObject = new Amendment__c();
    	amendmentObject.RecordTypeId = [SELECT ID FROM RecordType where SObjectType =: 'Amendment__c' AND IsActive =: true AND DeveloperName =: 'Location_Amendment_New_Key'].Id;
    	amendmentObject.Account__c = accountObject.Id;
    	insert amendmentObject;
    	
    	//For Account Location..
    	Account_Location__c accLocationObject = new Account_Location__c();
    	accLocationObject.New_Location__c = locationObject2.Id;
    	accLocationObject.Account__c = accountObject.Id;
    	insert accLocationObject;
    	
    	//For SLA...
    	//SLA Implementation...
    	List<SLA__c> slaList = new List<SLA__c>();
    	
        SLA__c slaObject1 = new SLA__c();
        slaObject1.License__c = accountObject.Id;
        slaObject1.Actual_Start_Date_Time__c= DateTime.Now();
        slaObject1.Expected_End_Date__c= DateTime.Now().addYears(2);
        slaObject1.SLA_Hours__c = 100;
        slaObject1.Process_Type__c = 'License';
        slaObject1.Application_Type__c = 'Renewal';
        slaObject1.Actual_End_Date_Time__c= DateTime.Now().addYears(1);
        //Adding in teh List...
        slaList.add(slaObject1);
        
        SLA__c slaObject2 = new SLA__c();
        slaObject2.License__c = accountObject.Id;
        slaObject2.Actual_Start_Date_Time__c= DateTime.Now();
        slaObject2.Expected_End_Date__c= DateTime.Now().addYears(2);
        slaObject2.SLA_Hours__c = 100;
        slaObject2.Process_Type__c = 'License';
        slaObject2.Application_Type__c = 'Cancellation';
        slaObject2.Actual_End_Date_Time__c= DateTime.Now().addYears(1);
        //Adding in teh List...
        slaList.add(slaObject2);
        
        SLA__c slaObject3 = new SLA__c();
        slaObject3.License__c = accountObject.Id;
        slaObject3.Actual_Start_Date_Time__c= DateTime.Now();
        slaObject3.Expected_End_Date__c= DateTime.Now().addYears(2);
        slaObject3.SLA_Hours__c = 100;
        slaObject3.Process_Type__c = 'License';
        slaObject3.Application_Type__c = 'Renewal Amendment - Add Location';
        slaObject3.Actual_End_Date_Time__c= DateTime.Now().addYears(1);
        //Adding in teh List...
        slaList.add(slaObject3);
        
        SLA__c slaObject4 = new SLA__c();
        slaObject4.License__c = accountObject.Id;
        slaObject4.Actual_Start_Date_Time__c= DateTime.Now();
        slaObject4.Expected_End_Date__c= DateTime.Now().addYears(2);
        slaObject4.SLA_Hours__c = 100;
        slaObject4.Amendment__c = amendmentObject.Id;
        slaObject4.Process_Type__c = 'Amendment';
        slaObject4.Application_Type__c = amendmentObject.Record_Type_Name__c;
        slaObject4.Actual_End_Date_Time__c= DateTime.Now().addYears(1);
        //Adding in teh List...
        slaList.add(slaObject4);
        
        SLA__c slaObject5 = new SLA__c();
        slaObject5.License__c = accountObject.Id;
        slaObject5.Actual_Start_Date_Time__c= DateTime.Now();
        slaObject5.Expected_End_Date__c= DateTime.Now().addYears(2);
        slaObject5.SLA_Hours__c = 100;
        slaObject5.Process_Type__c = 'License';
        slaObject5.Application_Type__c = 'Tenancy Renewal';
        slaObject5.Tenancy_Contract__c = tenancyObject.Id;
        slaObject5.Actual_End_Date_Time__c= DateTime.Now().addYears(1);
        //Adding in teh List...
        slaList.add(slaObject5);
        
    	//Inserting in the List...
    	if(slaList.size() > 0)
    		upsert slaList;
    		
    	//Now Calling the Methods...
    	result = ctrl_CancelProcess.cancelProcessButtonMethod(accountObject.Id, tenancyObject.id, 'Tenancy', 'Tenancy Renewal');
    	//Now Calling the Methods...
    	result = ctrl_CancelProcess.cancelProcessButtonMethod(accountObject.Id, accountObject.id, 'Account', 'Cancellation');
    	//Now Calling the Methods...
    	result = ctrl_CancelProcess.cancelProcessButtonMethod(accountObject.Id, accountObject.id, 'Account', 'Renewal');
    	//Now Calling the Methods...
    	result = ctrl_CancelProcess.cancelProcessButtonMethod(accountObject.Id, accountObject.id, 'Account', 'Renewal Amendment - Add Location');
    	//Now Calling the Methods...
    	result = ctrl_CancelProcess.cancelProcessButtonMethod(accountObject.Id, amendmentObject.id, 'Amendment', amendmentObject.Record_Type_Name__c);

    
    }
}